<?php
namespace App\Common\Server\Api\Gateway\ApiRequest;

use App\Common as com;
use App as nameApp;
use App\Common\Server\Api as nameApi;
use App\Common\Server\Api\Gateway as nameGateway;

class ApiAuth extends nameApi\Base {

	/**
	 * ApiRouter constructor.
	 * @param nameGateway\ApiRequest $apiRequest api请求对象
	 * @throws
	 */
	public function __construct( nameGateway\ApiRequest $apiRequest ) {
		$this->goWeakReferencePool()->create( 'apiRequest', $apiRequest );
		parent::__construct();
	}

	/**
	 * 获取 apiRequest 对象
	 * @return nameGateway\ApiRequest
	 * @throws
	 */
	private function apiRequest(  ):nameGateway\ApiRequest {
		return $this->goWeakReferencePool()->get( 'apiRequest' );
	}

	/**
	 * 是否允许执行
	 * @return bool [true]允许 [false]不允许
	 * @throws
	 */
	public function check():bool {
		// 检查权限
		return $this->apiRequest()->accessToken()->auth()->check(
			$this->apiRequest()->apiData()->getApiNameFull()
		);
	}

}
